\def\tankdim{2.5}
\def\tankthick{4pt}
\def\arrowthick{4pt}
\def\valvewidth{0.5}
\def\valveheight{0.25}
\def\valvethick{2pt}
% \newcommand{\glsgraphcmd}[1]{\glsentryname{#1}}
% \newcommand{\glsgraph}[1]{\ensuremath{\bm{\glsgraphcmd{#1}}}}

\definecolor{tankcolor}{RGB}{55,201,250}
\definecolor{compcolor}{RGB}{211,231,234}
\definecolor{valvecolor}{RGB}{55,201,250}
\definecolor{inputcolor}{RGB}{237,7,34}
\definecolor{statecolor}{RGB}{57,204,101}
\definecolor{bccolor}{RGB}{255,171,25}

\def\inputtext#1{\Large\textcolor{inputcolor}{#1}}
\def\statetext#1{\Large\textcolor{statecolor}{#1}}
\def\bctext#1{\Large\textcolor{bccolor}{#1}}

\newcommand{\drawtank}[2]{
  \draw[line width=\tankthick, draw=tankcolor] #1 rectangle #2;
}

\newcommand{\drawvalve}[3][]{
  \draw[line width=\valvethick, draw=tankcolor, fill=tankcolor, #1] (#2) -- +(\valvewidth, \valveheight) -- +(\valvewidth, -\valveheight) -- +(-\valvewidth, \valveheight) -- +(-\valvewidth, -\valveheight) -- cycle;
  \draw[line width=3pt, draw=gray, #1] (#2) -- ++(0,#3) -- +(#3/2,0) -- +(-#3/2,0);
}

\newcommand{\drawflow}[3][]{
  \draw[line width=\arrowthick, draw=black, #1] #2 -- #3;
}

\newcommand{\drawcomp}{%
    % Tanks
  \drawtank{(0,0) coordinate (itank-bl)}{(2.5,2.5) coordinate (itank-tr)}
  \drawtank{(9,-1) coordinate(otank-tl)}{++(\tankdim,-\tankdim) coordinate (otank-br)}

    % Compressor
  \draw[line width=0,draw=compcolor,fill=compcolor] (4.5,1) coordinate (comp-tl) {} -- ++(2.5,-0.5) -- ++(0,-3) coordinate (comp-br) {} -- ++(-2.5,-0.5) coordinate (comp-bl) -- cycle;

  \coordinate (itank-2comp) at ($(\tankdim,1) + (0.5*\tankthick,0)$) {};
  \coordinate (otank-2comp) at ($(comp-br) + (3,0)$){};

    % Valves
  \coordinate (ivalve) at ($(itank-tr) + (-0.5*\tankdim, 1) + (0, \valvewidth)$); 
  \coordinate (ovalve) at ($(otank-tl) + (0.5*\tankdim, 1) + (0, \valvewidth)$);
  \coordinate (rvalve) at ($(comp-br) + (-1.25,-2.5)$);
  \iftoggle{compfirstvalve}{
    \drawvalve[rotate=90, transform shape]{ivalve}{0.4}
  }{}
  \drawvalve[rotate=90, transform shape]{ovalve}{0.4}
  \drawvalve{rvalve}{-0.4}

  % Labels and Text
    % Nodes
      \node[above, align=center] at ($(rvalve)+(0,\valveheight)$) {Recycle Valve\\\statetext{\glsgraph{qr}}};
        \node[below, rotate=90, transform shape] at ($(ivalve)+(\valveheight,0)$) {Suction Valve};
      \node[below, rotate=90, transform shape] at ($(ovalve)+(\valveheight,0)$) {Discharge Valve};
      \node[above, align=center] at ($(rvalve)+(0,\valveheight)$) {\statetext{\glsgraph{qr}}};


      \draw[<-,draw=inputcolor,line width=2pt] ($(ivalve)-(2*\valveheight,0)$) -- ++(-1,0) node[below]{\inputtext{\glsgraph{us}}};

    \draw[<-,draw=inputcolor,line width=2pt] ($(ovalve)-(2*\valveheight,0)$) -- ++(-1,0) coordinate (x);
    \node[below] at (x) {\inputtext{\glsgraph{ud}}};
    \draw[<-,draw=inputcolor,line width=2pt] ($(rvalve)-(0,2*\valveheight)$) -- ++(0,-1) coordinate (x);
    \node[right] at ($(x)+(0,0.5)$) {\inputtext{\glsgraph{ur}}};
    \draw[<-,draw=inputcolor,line width=2pt] (comp-tl |- comp-br) -- ++(-1,0) coordinate (x);
    \node[above] at (x) {\inputtext{\glsgraph{torque}}};

      \node[align=center] at ($0.5*(itank-tr)+0.5*(itank-bl)$) {Suction\\Tank};
      \node[align=center] at ($0.5*(otank-br)+0.5*(otank-tl)$) {Discharge\\Tank};
      \node[align=center] at ($0.5*(comp-tl)+0.5*(comp-br |- comp-bl)$) {Compressor};

    % Gas flow
    \drawflow[<-]{($(ivalve)+(0,\valvewidth)+(0,0.5*\valvethick)$)}{+(0,1)}
    \drawflow[->]{($(ivalve)-(0,\valvewidth)-(0,0.5*\valvethick)$)}{($(ivalve |- itank-tr) + (0, 0.5*\tankthick)$)}

  \drawflow[->]{(itank-2comp)}{(comp-tl)};
  \drawflow[->]{(comp-br)}{($(otank-tl |- comp-br) - (0.5*\tankthick, 0)$)};

  \drawflow[->]{($(otank-br)-(0.5*\tankdim,0.5*\tankthick)$)}{+(0,0) |- ($(rvalve)+(\valvewidth,0) + (0.5*\valvethick,0)$) coordinate (x)}
  \drawflow[->]{($(x) - (\valvethick,0) - (2*\valvewidth,0)$) coordinate (z)}{+(0,0) -| ($(itank-bl) + (0.5*\tankdim,-0.5*\tankthick)$)}

  \drawflow[<-]{($(ovalve)-(0,\valvewidth)-(0,0.5*\valvethick)$)}{($(ovalve |- otank-tl) + (0, 0.5*\tankthick)$)}
  \drawflow[->]{($(ovalve)+(0,\valvewidth)+(0,0.5*\valvethick)$)}{+(0,1)}

}


